<template>
	<a-card style="margin: -15px">
		<a-tabs v-model:activeKey="formState.conType" @change="tabsChange" type="card">
			<a-tab-pane key="0" tab="普通空投任务">
				<a-row style="margin-bottom: 1rem">
					<a-col :span="6">
						<a-input-search
							v-model:value=this.page.airName
							placeholder="根据任务名称模糊搜索"
							enter-button="搜索"
							size="large"
							@search="onSearch"
						/>
					</a-col>
					<!--放置搜索条件-->
					<a-col :span="3">

					</a-col>
					<a-col :push=this.number :span="2">
						<a-button type="primary" style="width: 90px;height: 40px" @click="showDrawer()">
							<PlusOutlined/>
							添加
						</a-button>
					</a-col>
				</a-row>
				<a-row style="margin-bottom: 1rem">
					<a-col :span="24">
						<a-table :columns="columns" :data-source="data" :pagination="false" @change="onChange">
							<template #bodyCell="{ column, record }">
								<!--空投藏品-->
								<template v-if="column.key === 'airNft'">
									<a-row style="margin-top: 0.5rem" :wrap="false"
										   v-for="airNft in record.opAirNftVos">
										<a-col>
											<img :src="airNft.nftCover" width="50" height="50">
										</a-col>
										<a-col style="margin: auto 2px;white-space:nowrap">
											<a @click="this.$refs.gatNftInfo.getNft(airNft.nftId)">{{
													airNft.nftName
												}}</a>
											<br/>
											X{{ airNft.num }}
										</a-col>
									</a-row>
								</template>
								<!--空投条件项-->
								<template v-if="column.key === 'airHold'">
									<a-row style="margin-top: 0.5rem" :wrap="false"
										   v-for="airHold in record.opAirHoldLimitVos">
										<a-col>
											<img :src="airHold.nftCover" width="50" height="50">
										</a-col>
										<a-col style="margin: auto 2px;white-space:nowrap">
											<a @click="this.$refs.gatNftInfo.getNft(airHold.nftId)">{{
													airHold.nftName
												}}</a>
											<br/>
											X{{ airHold.holdNum }}
										</a-col>
									</a-row>


								</template>
								<!--状态-->
								<template v-if="column.key === 'status'">
									<a-tag v-if="record.status==0" :bordered="false" color="default">未启用</a-tag>
									<a-tag v-if="record.status==1" :bordered="false" color="orange">待快照</a-tag>
									<a-tag v-if="record.status==2" :bordered="false" color="error">待执行</a-tag>
									<!--									<a-tag v-if="record.status==3" :bordered="false" color="success">已结束</a-tag>-->
									<a-tag v-if="record.status==4" :bordered="false" color="success">已结束</a-tag>
								</template>
								<!--资格名单-->
								<template v-if="column.key === 'airList'">
									<a-tag :bordered="false" color="success" style="cursor: pointer"
										   @click="viewAirList(record.id)">
										查看资格名单
									</a-tag>
								</template>
								<!--操作-->
								<template v-if="column.key === 'action'">
									<a-dropdown>
										<template #overlay>
											<a-menu @click="handleMenuClick($event,record.id)">
												<a-menu-item key="1" v-if="record.status==0">
													启用
												</a-menu-item>
												<a-menu-item key="2" v-if="record.status==1">
													禁用
												</a-menu-item>
												<a-menu-item key="3" v-if="record.status==0">
													编辑
												</a-menu-item>
												<a-menu-item key="4">
													查看
												</a-menu-item>
												<a-menu-item key="5" v-if="record.status==0">
													删除
												</a-menu-item>
												<a-menu-item key="6" v-if="record.status==1">
													快照
												</a-menu-item>
												<a-menu-item key="7" v-if="record.status==4">
													查看空投记录
												</a-menu-item>
												<a-menu-item key="8" v-if="record.status==2">
													执行空投
												</a-menu-item>
												<a-menu-item key="9" v-if="record.status>1">
													查看执行记录
												</a-menu-item>
											</a-menu>
										</template>
										<a-button>
											操作
											<DownOutlined/>
										</a-button>
									</a-dropdown>
								</template>
							</template>
						</a-table>
					</a-col>
				</a-row>
				<a-flex justify="flex-end">
					<a-pagination
						size="small"
						v-model:current="this.page.pageNo"
						v-model:page-size="this.page.pageSize"
						:total="this.page.total"
						show-size-changer
						:pageSizeOptions="['5','10','20','50','100']"
						:show-total="(total, range) => `${range[0]}-${range[1]} 共 ${total} 条`"
						@change="onChange"
					/>
				</a-flex>
			</a-tab-pane>
			<a-tab-pane key="1" tab="特殊空投任务" force-render>
				<a-row style="margin-bottom: 1rem">
					<a-col :span="6">
						<a-input-search
							v-model:value=this.page.airName
							placeholder="根据任务名称模糊搜索"
							enter-button="搜索"
							size="large"
							@search="onSearch"
						/>
					</a-col>
					<!--放置搜索条件-->
					<a-col :span="3">


					</a-col>

					<a-col :push=this.number :span="2">

						<a-button type="primary" style="width: 90px;height: 40px" @click="showDrawer()">
							<PlusOutlined/>
							添加
						</a-button>
					</a-col>

				</a-row>
				<a-row style="margin-bottom: 1rem">
					<a-col :span="24">
						<a-table :columns="speColumns" :data-source="data" :pagination="false" @change="onChange">
							<template #bodyCell="{ column, record }">
								<!--状态-->
								<template v-if="column.key === 'status'">
									<a-tag v-if="record.status==0" :bordered="false" color="default">未启用</a-tag>
									<a-tag v-if="record.status==2" :bordered="false" color="error">待执行</a-tag>
									<a-tag v-if="record.status==3" :bordered="false" color="processing">进行中</a-tag>
									<a-tag v-if="record.status==4" :bordered="false" color="success">已结束</a-tag>
								</template>

								<!--资格名单-->
								<template v-if="column.key === 'airList'">
									<a-tag :bordered="false" color="success" style="cursor: pointer"
										   @click="viewSpeAirList(record.id)">
										查看特殊投递人名单
									</a-tag>
								</template>

								<!--操作-->
								<template v-if="column.key === 'action'">
									<a-dropdown>
										<template #overlay>
											<a-menu @click="handleMenuClick($event,record.id)">
												<a-menu-item key="1" v-if="record.status==0">
													启用
												</a-menu-item>
												<a-menu-item key="2" v-if="record.status==2">
													禁用
												</a-menu-item>
												<a-menu-item key="3" v-if="record.status==0">
													编辑
												</a-menu-item>
												<a-menu-item key="4">
													查看
												</a-menu-item>
												<a-menu-item key="5" v-if="record.status==0">
													删除
												</a-menu-item>
												<a-menu-item key="7" v-if="record.status==3">
													查看空投记录
												</a-menu-item>
												<a-menu-item key="8" v-if="record.status==2">
													执行空投
												</a-menu-item>
												<a-menu-item key="9" v-if="record.status>1">
													查看执行记录
												</a-menu-item>
											</a-menu>
										</template>
										<a-button>
											操作
											<DownOutlined/>
										</a-button>
									</a-dropdown>
								</template>
							</template>
						</a-table>
					</a-col>
				</a-row>
				<a-flex justify="flex-end">
					<a-pagination
						size="small"
						v-model:current="this.page.pageNo"
						v-model:page-size="this.page.pageSize"
						:total="this.page.total"
						:pageSizeOptions="['5','10','20','50','100']"
						show-size-changer
						:show-total="(total, range) => `${range[0]}-${range[1]} 共 ${total} 条`"
						@change="onChange"
					/>
				</a-flex>
			</a-tab-pane>
		</a-tabs>

		<!--  添加修改抽屉-->
		<a-drawer :width="drawer.width" :title='formState.id==null?"添加空投任务":"编辑空投任务"'
				  :placement="drawer.placement" :visible="drawer.open"
				  @close="onClose">
			<template #extra>
				<a-button style="margin-right: 8px" @click="onClose">取消</a-button>
				<a-button type="primary" @click="saveAirInfo">保存</a-button>
			</template>

			<a-form layout="vertical"
					ref="formRef"
					:model="formState">

				<a-card title="基本信息">

					<a-row :gutter="16">
						<a-col :span="12">
							<a-form-item ref="conType" label="任务类型" name="conType">
								<a-radio-group :value="formState.conType" disabled>
									<a-radio-button value="0">普通空投任务</a-radio-button>
									<a-radio-button value="1">特殊空投任务</a-radio-button>
								</a-radio-group>
							</a-form-item>
						</a-col>
						<a-col :span="12">
							<a-form-item ref="name" label="任务名称" name="name" :rules="{required:true}">
								<a-input v-model:value="formState.name" placeholder="活动名称"/>
							</a-form-item>
						</a-col>
					</a-row>
					<a-row :gutter="16" v-if="formState.conType==0">
						<a-col :span="12">
							<a-form-item label="快照时间" required name="snaTime"
										 :rules="{ validator: validateStartTime,required: true,trigger: ['change', 'blur']}">
								<a-date-picker
									v-model:value="formState.snaTime"
									value-format="YYYY-MM-DD HH:mm:ss"
									show-time
									type="date"
									placeholder="选择快照时间"
									style="width: 100%"
								/>
							</a-form-item>
						</a-col>
						<a-col :span="12">
							<a-form-item label="执行时间" required name="exeTime"
										 :rules="{ validator: validateEndTime,required: true,trigger: ['change', 'blur']}">
								<a-date-picker
									v-model:value=formState.exeTime
									value-format="YYYY-MM-DD HH:mm:ss"
									show-time
									type="date"
									placeholder="选择执行时间"
									style="width: 100%"
								/>
							</a-form-item>
						</a-col>
					</a-row>
					<a-row :gutter="16" v-if="formState.conType==1">
						<a-col :span="12">
							<a-form-item label="全局空投的时间" required name="exeTime"
										 :rules="{ validator: validateSpeExeTime,required: true,trigger: ['change', 'blur']}">
								<a-date-picker
									v-model:value="formState.exeTime"
									value-format="YYYY-MM-DD HH:mm:ss"
									show-time
									type="date"
									placeholder="选择全局空投的时间"
									style="width: 100%"
								/>
							</a-form-item>
						</a-col>
						<a-col :span="12">
							<a-form-item label="投递类型" required name="deliveryType"
										 :rules="{required:true,message:'请选择投递类型'}">
								<a-select v-model:value="formState.deliveryType"
										  style="width: 100%" placeholder="选择投递类型">
									<a-select-option value="0">合成</a-select-option>
									<a-select-option value="1">空投</a-select-option>
									<a-select-option value="2">优先购</a-select-option>
								</a-select>
							</a-form-item>
						</a-col>
					</a-row>
				</a-card>

				<a-card title="空投条件" v-if="formState.conType==0">
					<a-row :gutter="16" v-for="(airHoldLimit, index) in formState.opAirHoldLimitBos">
						<a-col :span="12">
							<a-form-item :name="['opAirHoldLimitBos', index, 'nftId']"
										 :rules="{required: true,message:'请选持有艺术品'}">
								<a-select
									v-model:value="airHoldLimit.nftId" show-search :options="filterInfo.options"
									:field-names="filterInfo.fieldNames"
									option-filter-prop="name" placeholder="持有艺术品" style="width:100%">
								</a-select>
							</a-form-item>
						</a-col>
						<a-col :span="10">
							<a-form-item
								:name="['opAirHoldLimitBos', index, 'holdNum']"
								:rules="{required: true,message:'请输入持有数量'}">
								<a-input-number v-model:value="airHoldLimit.holdNum" :min="1" placeholder="持有数量"
												:max="100000"
												style="width:100%"/>
							</a-form-item>
						</a-col>
						<a-col :span="2">
							<MinusCircleOutlined @click="removeAirHoldLimit(airHoldLimit)"
												 style="margin-top: 0.4rem;font-size: 1.2rem;opacity: 0.5"/>
						</a-col>
					</a-row>
					<a-row :gutter="16">
						<a-col :span="22">
							<a-button type="dashed" block @click="addAirHoldLimit">
								<PlusOutlined/>
								增加持有条件
							</a-button>
						</a-col>
					</a-row>
				</a-card>

				<a-card title="空投艺术品" v-if="formState.conType==0">
					<a-row :gutter="16" v-for="(airNftBo, index) in formState.opAirNftBos">
						<a-col :span="12">
							<a-form-item
								:name="['opAirNftBos', index, 'nftId']"
								:rules="{required: true,message: '请选持有艺术品',}">
								<a-select
									v-model:value="airNftBo.nftId"
									show-search
									:options="filterInfo.airOptions"
									:field-names="filterInfo.fieldNames"
									option-filter-prop="name"
									placeholder="空投艺术品"
									style="width: 100%"></a-select>
							</a-form-item>
						</a-col>
						<a-col :span="10">


							<a-form-item
								:name="['opAirNftBos', index, 'num']"
								:rules="{required: true,message: '请输入空投数量'}">
								<a-input-number v-model:value="airNftBo.num" :min="1" placeholder="空投数量"
												:max="100000"
												style="width:100%"/>
							</a-form-item>
						</a-col>
						<a-col :span="2">
							<MinusCircleOutlined @click="removeAirNft(airNftBo)"
												 style="margin-top: 0.4rem;font-size: 1.2rem;opacity: 0.5"/>
						</a-col>
					</a-row>
					<a-row :gutter="16">
						<a-col :span="22">
							<a-button type="dashed" block @click="addAirNft">
								<PlusOutlined/>
								增加空投艺术品
							</a-button>
						</a-col>
					</a-row>
				</a-card>

				<a-card title="特殊投递人" v-if="formState.conType==1">
					<a-row :gutter="16" v-for="(airListBo, index) in formState.opAirListBos">

						<a-col :span="6">
							<a-form-item ref="name"
										 :name="['opAirListBos', index, 'mbPhone']"
										 :rules="{required: true,message:'请输入会员手机号'}">
								<a-input v-model:value="airListBo.mbPhone" placeholder="会员手机号"/>
							</a-form-item>
						</a-col>

						<a-col :span="6">
							<a-form-item :name="['opAirListBos', index, 'nftId']"
										 :rules="{required: true,message:'请选空投艺术品'}">
								<a-select
									v-model:value="airListBo.nftId" show-search :options="filterInfo.options"
									:field-names="filterInfo.fieldNames"
									option-filter-prop="name" placeholder="空投艺术品" style="width:100%">
								</a-select>
							</a-form-item>
						</a-col>
						<a-col :span="3">
							<a-form-item
								:name="['opAirListBos', index, 'count']"
								:rules="{required: true,message:'不能为空'}">
								<a-input-number v-model:value="airListBo.count" placeholder="数量" :min="1"
												:max="100000"
												style="width:100%"/>
							</a-form-item>
						</a-col>

						<a-col :span="7">
							<a-form-item
								:name="['opAirListBos', index, 'exeTime']"
								:rules="{ validator: validateSpeAirTime,required: true,trigger: ['change', 'blur']}">
								<a-date-picker
									v-model:value="airListBo.exeTime"
									value-format="YYYY-MM-DD HH:mm:ss"
									show-time
									type="date"
									placeholder="特殊投递时间"
									style="width: 100%"
								/>
							</a-form-item>
						</a-col>
						<a-col :span="2">
							<MinusCircleOutlined @click="removeList(airListBo)"
												 style="margin-top: 0.4rem;font-size: 1.2rem;opacity: 0.5"/>
						</a-col>
					</a-row>
					<a-row :gutter="16">
						<a-col :span="22">
							<a-button type="dashed" block @click="addList">
								<PlusOutlined/>
								增加加特殊投递人
							</a-button>
						</a-col>
					</a-row>
				</a-card>
			</a-form>

		</a-drawer>

		<!--  查看模态窗口-->
		<a-modal title="空投任务信息" v-model:open="openModal" style="width: 700px" :footer="null">
			<a-card title="基本信息">
				<a-descriptions :column="2">
					<a-descriptions-item label="任务名称">{{ this.airdropInfo.name }}</a-descriptions-item>
					<a-descriptions-item label="任务类型">{{
							this.airdropInfo.conType == '0' ? '普通空投任务' : '特殊空投任务'
						}}
					</a-descriptions-item>
					<a-descriptions-item v-if="this.airdropInfo.conType=='0'" label="快照时间">
						{{ this.airdropInfo.snaTime }}
					</a-descriptions-item>
					<a-descriptions-item v-if="this.airdropInfo.conType=='0'" label="执行时间">
						{{ this.airdropInfo.exeTime }}
					</a-descriptions-item>
					<a-descriptions-item v-if="this.airdropInfo.conType=='1'" label="全局投递时间">
						{{ this.airdropInfo.exeTime }}
					</a-descriptions-item>
				</a-descriptions>
				<a-descriptions :column="2">
					<a-descriptions-item label="创建人">{{ this.airdropInfo.createUser }}</a-descriptions-item>
					<a-descriptions-item label="创建时间">{{ this.airdropInfo.createTime }}</a-descriptions-item>
					<a-descriptions-item label="更新人">{{ this.airdropInfo.updateUser }}</a-descriptions-item>
					<a-descriptions-item label="更新时间">{{ this.airdropInfo.updateTime }}</a-descriptions-item>
				</a-descriptions>
			</a-card>

			<a-card title="特殊投递人员" v-if="airdropInfo.conType=='1'">
				<a-table :columns="airListCols" :data-source="airdropInfo.opAirListVos" :pagination="false"
						 @change="onChange">
					<template #bodyCell="{ column, record }">
						<!--空投藏品-->
						<template v-if="column.key === 'airNft'">
							<a-row align="middle" :wrap="false" :gutter="[16,16]">
								<a-col>
									<a-avatar :src=record.nftCover shape="square" size="large"/>
								</a-col>
								<a-col>{{ record.nftName }}</a-col>
							</a-row>

						</template>
					</template>
				</a-table>
			</a-card>
			<a-card title="空投条件" v-if="airdropInfo.conType=='0'">
				<a-table :columns="conditionCols" :data-source="airdropInfo.opAirHoldLimitVos" :pagination="false"
						 @change="onChange">
					<template #bodyCell="{ column, record }">
						<!--空投藏品-->
						<template v-if="column.key === 'nftName'">
							<a-row align="middle" :wrap="false" :gutter="[16,16]">
								<a-col>
									<a-avatar :src=record.nftCover shape="square" size="large"/>
								</a-col>
								<a-col>{{ record.nftName }}</a-col>
							</a-row>

						</template>
					</template>
				</a-table>
			</a-card>
			<a-card title="空投藏品" v-if="airdropInfo.conType=='0'">
				<a-table :columns="airNftCols" :data-source="airdropInfo.opAirNftVos" :pagination="false"
						 @change="onChange">
					<template #bodyCell="{ column, record }">
						<!--空投藏品-->
						<template v-if="column.key === 'airNft'">
							<a-row align="middle" :wrap="false">
								<a-col>
									<a-avatar :src=record.nftCover shape="square" size="large"/>
								</a-col>
								<a-col>{{ record.nftName }}</a-col>
							</a-row>

						</template>
					</template>
				</a-table>
			</a-card>

		</a-modal>

		<!--  查看资格名单模态窗口-->
		<a-modal title="查看资格名单" v-model:open="airListModal" style="width: 700px" :footer="null">

			<a-card>
				<a-flex justify="flex-start" style="margin-bottom: 1rem">
					<a-input-search
						style="width: 220px"
						v-model:value="eligibilityList.phone"
						placeholder="手机号模糊查询"
						enter-button="搜索"
						@search="airListChange(1,null)"
					/>
				</a-flex>

				<a-table :columns="eligibilityList.columns" :data-source="eligibilityList.airList"
						 :pagination="eligibilityList.pagination"
						 @change="value => airListChange(value.current,value.pageSize)">
					<template #bodyCell="{ column, record }">
						<!--空投藏品-->
						<template v-if="column.key === 'mbName'">
							<a @click="this.$refs.getMb.showGetMb(record.mbId)">{{ record.mbName }}</a>
						</template>
					</template>
				</a-table>
			</a-card>
		</a-modal>

		<!--  查看特殊投递人名单模态窗口-->
		<a-modal title="查看特殊投递人名单" v-model:open="speDeliveryList.openModal" style="width: 900px"
				 :footer="null">

			<a-card>
				<a-row style="margin-bottom: 1rem">
					<a-col>
						<a-input-search
							v-model:value="speDeliveryList.phone"
							placeholder="手机号模糊查询"
							enter-button="搜索"
							@search="airDelListChange(1,null)"
						/>
					</a-col>
				</a-row>
				<a-table :columns="speDeliveryList.columns" :data-source="speDeliveryList.airList"
						 :pagination="speDeliveryList.pagination"
						 @change="value=>airDelListChange(value.current,value.pageSize)">
					<template #bodyCell="{ column, record }">
						<!--会员-->
						<template v-if="column.key === 'mbName'">
							<a @click="this.$refs.getMb.showGetMb(record.mbId)">{{ record.mbName }}</a>
						</template>
						<!--空投藏品-->
						<template v-if="column.key === 'airNft'">
							<a-row align="middle" :wrap="false" :gutter="[16,16]">
								<a-col>
									<a-avatar :src=record.nftCover shape="square" size="large"/>
								</a-col>
								<a-col>
									<a @click="this.$refs.gatNftInfo.getNft(record.nftId)">{{ record.nftName }}</a>
								</a-col>
							</a-row>

						</template>
					</template>
				</a-table>
			</a-card>
		</a-modal>

		<!--  查看空投记录模态窗口-->
		<a-modal title="查看空投记录" v-model:open="airdropLog.openModal" style="width: 950px" :footer="null">
			<a-row style="margin-bottom: 1rem">
				<a-col>
					<a-input-search
						v-model:value="airdropLog.keyword"
						placeholder="手机号模糊查询"
						enter-button="搜索"
						size="large"
						@search="airdropLogChange(1)"
					/>
				</a-col>
			</a-row>
			<a-card>
				<a-table :columns="airdropLog.columns" :data-source="airdropLog.airLogList"
						 :pagination="this.airdropLog.pagination"
						 @change="airdropLogChange(0)">
					<template #bodyCell="{ column, record }">
						<!--空投藏品-->
						<template v-if="column.key === 'airNft'">
							<a-row align="middle" :wrap="false" :gutter="[16,16]">
								<a-col>
									<a-avatar :src=record.nftCover shape="square" size="large"/>
								</a-col>
								<a-col>{{ record.nftName }}</a-col>
							</a-row>

						</template>
					</template>
				</a-table>
			</a-card>
		</a-modal>

		<!--  查看执行记录模态窗口-->
		<a-modal title="查看执行记录" v-model:open="airdropExeLog.openModal" style="width: 750px" :footer="null">
			<a-card>
				<a-table :columns="airdropExeLog.columns" :data-source="airdropExeLog.airExeLogList"
						 :pagination="false">
					<template #bodyCell="{ column, record }">
						<!--任务类型-->
						<template v-if="column.key === 'taskType'">
							<span>{{ record.taskType == '0' ? '快照' : '空投' }}</span>
						</template>
						<!--执行情况类型-->
						<template v-if="column.key === 'status'">
							<a-tag v-if="record.status==0" :bordered="false" color="success">成功</a-tag>
							<a-tag v-if="record.status==1" :bordered="false" color="error">失败</a-tag>
						</template>
					</template>
				</a-table>
			</a-card>
		</a-modal>
	</a-card>
</template>

<script>
import {message} from "ant-design-vue";
import airdropApi from "@/api/nft/activity/airdropApi";
import airListApi from "@/api/nft/activity/airListApi";
import {
	MinusCircleOutlined,
	PieChartOutlined,
	DesktopOutlined,
	UserOutlined,
	TeamOutlined,
	FileOutlined,
	PlusOutlined,
	DownOutlined,
} from '@ant-design/icons-vue';


export default {
	name: "Airdrop",

	components: {
		MinusCircleOutlined,
		PieChartOutlined,
		DesktopOutlined,
		UserOutlined,
		TeamOutlined,
		FileOutlined,
		PlusOutlined,
		DownOutlined,
	},
	data() {
		return {
			activeKey: '0',
			data: [],
			number: 13,
			pagination: 9,
			size: 20,
			page: {
				pageNo: 1,
				pageSize: 5,
				total: 0,
				airName: '',
				conType: '0',
			},
			columns: [
				{
					title: '任务名称',
					dataIndex: 'name',
					key: 'name',
				},
				{
					title: '空投艺术品',
					key: 'airNft',
				},
				{
					title: '空投条件',
					key: 'airHold',
				},
				{
					title: '状态',
					dataIndex: 'status',
					key: 'status',
				},
				{
					title: '资格名单',
					key: 'airList',
				},
				{
					title: '快照时间',
					dataIndex: 'snaTime',
					key: 'snaTime',
				},
				{
					title: '执行时间',
					dataIndex: 'exeTime',
					key: 'exeTime',
				},
				{
					title: '创建时间',
					dataIndex: 'createTime',
					key: 'createTime',
				},
				{
					title: '操作',
					key: 'action',
				},
			],
			speColumns: [
				{
					title: '任务名称',
					dataIndex: 'name',
					key: 'name',
				},
				{
					title: '特殊投递人名单',
					key: 'airList',
				},
				{
					title: '状态',
					dataIndex: 'status',
					key: 'status',
				},
				{
					title: '全局投递时间',
					dataIndex: 'exeTime',
					key: 'exeTime',
				},
				{
					title: '创建时间',
					dataIndex: 'createTime',
					key: 'createTime',
				},
				{
					title: '操作',
					key: 'action',
				},
			],
			conditionCols: [
				{
					title: '持有藏品',
					key: 'nftName',
				},
				{
					title: '持有数量',
					dataIndex: 'holdNum',
					key: 'holdNum',
				}
			],
			airNftCols: [
				{
					title: '空投藏品',
					key: 'airNft',
				},
				{
					title: '空投数量',
					dataIndex: 'num',
					key: 'num',
				}
			],
			airListCols: [
				{
					title: '会员手机号',
					dataIndex: 'mbPhone',
					key: 'mbPhone',
				},
				{
					title: '空投艺术品',
					key: 'airNft',
				},
				{
					title: '投递数量',
					dataIndex: 'count',
					key: 'count',
				},
				{
					title: '特殊投递时间',
					dataIndex: 'exeTime',
					key: 'exeTime',
				},
			],
			drawer: {
				width: 750,
				placement: 'right',
				open: false,
			},
			formState: {
				id: null,
				name: null,
				snaTime: null,
				exeTime: null,
				conType: '0',
				deliveryType: null,
				opAirHoldLimitBos: [
					{
						nftId: null,
						holdNum: null
					}],
				opAirListBos: [{
					mbId: null,
					mbPhone: null,
					nftId: null,
					count: null,
					exeTime: null
				}],
				opAirNftBos: [{
					nftId: null,
					num: null
				}],
			},
			filterInfo: {
				fieldNames: {label: 'name', value: 'id'},
				options: [],
				airOptions: [],
			},
			openModal: false,
			airListModal: false,
			airdropInfo: {
				name: null,
				snaTime: null,
				exeTime: null,
				conType: '0',
				createUser: null,
				createTime: null,
				updateUser: null,
				updateTime: null,
				opAirHoldLimitVos: [],
				opAirListVos: [],
				opAirNftVos: []
			},
			eligibilityList: {
				id: '',
				phone: '',
				columns: [
					{
						title: '会员名称',
						dataIndex: 'mbName',
						key: 'mbName',
					},
					{
						title: '会员手机号',
						dataIndex: 'mbPhone',
						key: 'mbPhone',
					},
					{
						title: '链上地址',
						dataIndex: 'chainAddr',
						key: 'chainAddr',
					},
					{
						title: '空投份数',
						dataIndex: 'count',
						key: 'count',
					}],
				airList: [],
				pagination: {
					current: 1,
					pageSize: 5,
					pageSizeOptions: ['5', '10', '20', '50', '100'],
					defaultPageSize: 5,
					total: 51,
					size: "small",
					showSizeChanger: true,
					showTotal: (total, range) => `${range[0]}-${range[1]} 共 ${total} 条`
				},

			},
			speDeliveryList: {
				id: '',
				phone: '',
				openModal: false,
				columns: [
					{
						title: '会员名称',
						dataIndex: 'mbName',
						key: 'mbName',
					},
					{
						title: '会员手机号',
						dataIndex: 'mbPhone',
						key: 'mbPhone',
					},
					{
						title: '链上地址',
						dataIndex: 'chainAddr',
						key: 'chainAddr',
					},
					{
						title: '空投藏品',
						key: 'airNft',
					},
					{
						title: '空投数量',
						dataIndex: 'count',
						key: 'count',
					}
				],
				airList: [],
				pagination: {
					current: 1,
					pageSize: 5,
					pageSizeOptions: ['5', '10', '20', '50', '100'],
					defaultPageSize: 5,
					total: 51,
					size: "small",
					showSizeChanger: true,
					showTotal: (total, range) => `${range[0]}-${range[1]} 共 ${total} 条`
				}
				,

			},
			airdropLog: {
				id: '',
				keyword:
					'',
				openModal:
					false,
				columns:
					[
						{
							title: '会员名称',
							dataIndex: 'mbName',
							key: 'mbName',
						},
						{
							title: '会员手机号',
							dataIndex: 'mbPhone',
							key: 'mbPhone',
						},
						{
							title: '链上地址',
							dataIndex: 'chainAddr',
							key: 'chainAddr',
						},
						{
							title: '空投藏品',
							key: 'airNft',
						},
						{
							title: '空投数量',
							dataIndex: 'num',
							key: 'num',
						},
						{
							title: '空投时间',
							dataIndex: 'airTime',
							key: 'airTime',
						}
					],
				airLogList:
					[],
				pagination:
					{
						current: 1,
						defaultPageSize:
							5,
						total:
							0,
						showQuickJumper:
							true,
					}
				,
			},
			airdropExeLog: {
				openModal: false,
				columns:
					[
						{
							title: '任务类型',
							dataIndex: 'taskType',
							key: 'taskType',
						},
						{
							title: '执行情况',
							dataIndex: 'status',
							key: 'status',
						},
						{
							title: '执行时间',
							dataIndex: 'exeTime',
							key: 'exeTime',
						},
						{
							title: '描述',
							dataIndex: 'remark',
							key: 'remark',
						}
					],
				airExeLogList:
					[],
			}
		}

	},
	methods: {
		//查询列表
		query() {
			debugger
			airdropApi.pageAirInfo(this.page.pageNo, this.page.pageSize, {
				airName: this.page.airName,
				conType: this.page.conType
			}).then((resp) => {
				debugger
				this.page.pageSize = resp.size;
				this.page.total = resp.total;
				this.data = resp.records;
			})
		},
		//搜索框查询事件
		onSearch() {
			//搜索之前先把页码置为1
			this.page.pageNo = 1;
			this.query();
		},
		//分页控件切换事件
		onChange(pageNo) {
			this.query();
			this.page.pageNo = pageNo;
		},
		//tab页切换事件
		tabsChange(newValue) {
			this.page.airName = '';
			this.data = [];
			//查询条件的类型
			this.page.conType = newValue;
			//对象的类型
			this.formState.conType = newValue;
			//调用查询事件
			this.onSearch();
		},
		//保存事件
		saveAirInfo() {
			debugger
			let formRef = this.$refs.formRef;
			formRef.validate().then(() => {
				debugger
				//特殊空投的执行时间给到快照时间
				if (this.formState.conType == 1) {
					this.formState.snaTime = this.formState.exeTime;
				}
				if (this.formState.id == null || this.formState.id === '') {
					debugger
					airdropApi.addAirInfo(this.formState).then((resp) => {
						debugger
						//关闭抽屉
						this.drawer.open = false
						//清空数据
						this.resetForm()
						//调用查询
						this.query()
					})
				} else {
					airdropApi.updateAirInfo(this.formState).then((resp) => {
						//关闭抽屉
						this.drawer.open = false
						//清空数据
						this.resetForm()
						//调用查询
						this.query()
					})
				}
			})
		},
		//下拉菜单事件
		handleMenuClick(e, id) {
			//启用
			if (e.key === '1') {
				airdropApi.enableAirInfo(id).then((resp) => {
					debugger
					this.query()
				})
			}
			//禁用
			if (e.key === '2') {
				airdropApi.disableAirInfo(id).then((resp) => {
					this.query()
				})
			}
			//修改查看
			if (e.key === '3') {
				airdropApi.getAirInfo(id).then((resp) => {
					//将vo转成bo
					let airInfoMap = new Map(Object.entries(resp));
					airInfoMap.set("opAirHoldLimitBos", airInfoMap.get("opAirHoldLimitVos"))
					airInfoMap.set("opAirListBos", airInfoMap.get("opAirListVos"))
					airInfoMap.set("opAirNftBos", airInfoMap.get("opAirNftVos"))
					airInfoMap.delete("opAirHoldLimitVos")
					airInfoMap.delete("opAirListVos")
					airInfoMap.delete("opAirNftVos")
					airInfoMap.delete("createUser")
					airInfoMap.delete("createTime")
					airInfoMap.delete("updateUser")
					airInfoMap.delete("updateTime")
					//map集合转对象
					this.formState = Object.fromEntries(airInfoMap)
					//弹出模态窗口并查询下拉框的值
					this.showDrawer();
				})
			}
			//查看空投活动
			if (e.key === '4') {
				airdropApi.getAirInfo(id).then((resp) => {
					this.airdropInfo = resp;
					this.openModal = true;

				})
			}
			//删除空投活动
			if (e.key === '5') {
				airdropApi.deleteAirdrop(id).then((resp) => {
					this.query()
				})
			}
			//执行快照
			if (e.key === '6') {
				airListApi.exeAirSna(id).then((resp) => {
					this.query()
				})
			}
			//查看记录快照
			if (e.key === '7') {
				this.viewAirdropLogList(id)
			}
			//执行空投活动
			if (e.key === '8') {
				airdropApi.exeAirdrop(id).then((resp) => {

				})
			}
			//查看执行日志
			if (e.key === '9') {
				airdropApi.getAirExeLogList(id).then((resp) => {

					//数据
					this.airdropExeLog.airExeLogList = resp;
					//打开模态窗口
					this.airdropExeLog.openModal = true;

				})
			}
		},

		//表单验证
		validateStartTime(rule, value, callback) {
			const snaTime = value
			const exeTime = this.formState.exeTime
			if (!value) return callback(new Error('快照时间不能为空'))
			if (snaTime) {
				const nowDate = new Date()
				if (nowDate > snaTime) {
					return callback(new Error('快照时间不能比当前时间早'))
				}
			}
			if (!exeTime) callback()
			if (snaTime && exeTime) {
				if (snaTime > exeTime) {
					return callback(new Error('快照时间时间不能早于执行时间'))
				}
			}
			callback()
		},
		validateEndTime(rule, value, callback) {
			const snaTime = this.formState.snaTime
			const exeTime = value
			if (!value) return callback(new Error('执行时间不能为空'))
			if (exeTime) {
				const nowDate = new Date()
				if (nowDate > exeTime) {
					return callback(new Error('执行时间不能比当前时间早'))
				}
			}
			if (!snaTime) callback()
			if (snaTime && exeTime) {
				// const startDate = new Date(startTime)
				// const endDate = new Date(endTime)
				if (exeTime <= snaTime) {
					return callback(new Error('执行时间不能晚于快照时间'))
				}
			}
			callback()
		},
		validateSpeExeTime(rule, value, callback) {
			const exeTime = value
			if (!value) return callback(new Error('全局空投时间不能为空'))
			if (exeTime) {
				const nowDate = new Date()
				if (nowDate > exeTime) {
					return callback(new Error('全局空投时间不能比当前时间早'))
				}
			}
			callback()
		},
		validateSpeAirTime(rule, value, callback) {
			const airTime = value
			if (airTime) {
				const nowDate = new Date()
				if (nowDate > airTime) {
					return callback(new Error('不能比当前时间早'))
				}
			}
			callback()
		},
		//资格名单列表切换事件
		airListChange(pageNo, pageSize) {
			debugger
			this.eligibilityList.pagination.current = pageNo;
			if (null != pageSize) {
				this.eligibilityList.pagination.pageSize = pageSize
			}

			this.viewAirList(this.eligibilityList.id)
		},
		airDelListChange(pageNo, pageSize) {
			debugger
			this.speDeliveryList.pagination.current = pageNo;
			if (null != pageSize) {
				this.speDeliveryList.pagination.pageSize = pageSize
			}

			this.viewSpeAirList(this.speDeliveryList.id)
		},
		airdropLogChange(type) {
			if (type == 1) {
				this.airdropLog.pagination.current = 1
			}
			this.viewAirdropLogList(this.airdropLog.id)
		},


		//关闭抽屉
		onClose() {
			this.resetForm();
			this.drawer.open = false
		},
		//打开抽屉
		showDrawer() {
			this.drawer.open = true
			//下拉框
			this.nftSelect()
		},
		//普通空投条件项移除
		removeAirHoldLimit(item) {
			debugger
			const index = this.formState.opAirHoldLimitBos.indexOf(item);
			let length = this.formState.opAirHoldLimitBos.length;
			if (index !== -1 && length > 1) {
				this.formState.opAirHoldLimitBos.splice(index, 1);
			}
		},
		//普通空投条件项添加
		addAirHoldLimit() {
			debugger
			this.formState.opAirHoldLimitBos.push({
				nftId: null,
				holdNum: null,
			})
		},
		//普通空投空投藏品项移除
		removeAirNft(item) {
			const index = this.formState.opAirNftBos.indexOf(item);
			let length = this.formState.opAirNftBos.length;
			if (index !== -1 && length > 1) {
				this.formState.opAirNftBos.splice(index, 1);
			}
		},
		//普通空投空投藏品项移除
		addAirNft() {
			this.formState.opAirNftBos.push({
				nftId: null,
				num: null,
			})
		},
		//特殊空投投递人移除
		removeList(item) {
			const index = this.formState.opAirListBos.indexOf(item);
			let length = this.formState.opAirListBos.length;
			if (index !== -1 && length > 1) {
				this.formState.opAirListBos.splice(index, 1);
			}
		},
		//特殊空投投递人添加
		addList() {
			this.formState.opAirListBos.push({
				mbId: null,
				nftId: null,
				count: null,
				exeTime: null
			})
		},
		//下拉框选项赋值
		nftSelect() {
			airdropApi.nftSelect(1, 100, null)
				.then((resp) => {
					console.log(resp)
					this.filterInfo.options = resp.records;
				})

			airdropApi.nftSelect(1, 100, 2)
				.then((resp) => {
					console.log(resp)
					this.filterInfo.airOptions = resp.records;
				})
		},
		//初始化表单绑定的对象
		resetForm() {
			let defFormState = {
				id: null,
				name: null,
				snaTime: null,
				exeTime: null,
				conType: '0',
				deliveryType: null,
				opAirHoldLimitBos: [
					{
						nftId: null,
						holdNum: null
					}],
				opAirListBos: [{
					mbId: null,
					mbPhone: null,
					nftId: null,
					count: null,
					exeTime: null
				}],
				opAirNftBos: [{
					nftId: null,
					num: null
				}],
			}
			defFormState.conType = this.formState.conType
			this.formState = defFormState;
			debugger
		},


		//查看资格名单查
		viewAirList(id) {
			this.eligibilityList.id = id
			let pageNo = this.eligibilityList.pagination.current;
			let pageSize = this.eligibilityList.pagination.pageSize;
			let data = {airId: id, phone: this.eligibilityList.phone}
			airListApi.getAirList(pageNo, pageSize, data).then((resp) => {
				debugger
				//分页信息
				this.eligibilityList.pagination.defaultPageSize = resp.size
				this.eligibilityList.pagination.total = resp.total
				//数据
				this.eligibilityList.airList = resp.records;
				//打开模态窗口
				this.airListModal = true;
			})
		},
		//查看特殊空投资格名单
		viewSpeAirList(id) {
			this.speDeliveryList.id = id
			let pageNo = this.speDeliveryList.pagination.current;
			let pageSize = this.speDeliveryList.pagination.pageSize;
			let data = {airId: id, phone: this.speDeliveryList.phone}

			airListApi.getAirList(pageNo, pageSize, data).then((resp) => {
				//分页信息

				this.speDeliveryList.pagination.defaultPageSize = resp.size
				this.speDeliveryList.pagination.total = resp.total
				//数据
				this.speDeliveryList.airList = resp.records;
				//打开模态窗口
				this.speDeliveryList.openModal = true;
			}).catch(() => {
				message.error("网络繁忙")
			})

		},
		//查看空投记录
		viewAirdropLogList(id) {
			debugger
			this.airdropLog.id = id
			let pageNo = this.airdropLog.pagination.current;
			let pageSize = this.airdropLog.pagination.defaultPageSize;
			let data = {airId: id, keyword: this.airdropLog.keyword};
			debugger
			airdropApi.pageAirLog(pageNo, pageSize, data).then((resp) => {
				debugger
				//分页信息
				this.airdropLog.pagination.defaultPageSize = resp.size
				this.airdropLog.pagination.total = resp.total
				//数据
				this.airdropLog.airLogList = resp.records;
				debugger
				//打开模态窗口
				this.airdropLog.openModal = true

			})
		},
	},
	mounted() {
		//界面加载完后调用查询
		this.query();
	}
}
</script>

<style scoped>
.pStyle {
	font-size: 16px;
	color: rgba(0, 0, 0, 0.85);
	line-height: 24px;
	display: block;
	margin-bottom: 16px;
}
</style>
